package com.ayu.shortlink.distribute.mq.consumer;

import com.ayu.shortlink.distribute.common.constant.RocketMQConstant;
import com.ayu.shortlink.distribute.mq.basics.base.MessageWrapper;
import com.ayu.shortlink.distribute.mq.basics.event.CouponTaskDelayExecuteEvent;
import com.ayu.shortlink.distribute.mq.basics.event.CouponTaskExecuteEvent;
import com.ayu.shortlink.distribute.mq.producer.CouponTaskExecuteProducer;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 延迟任务发送消费者
 */
@Component
@RequiredArgsConstructor
@RocketMQMessageListener(
        topic = RocketMQConstant.TOPIC_EXECUTOR_DELAY_TASK,
        consumerGroup = RocketMQConstant.GROUP_DELAY_EXECUTOR_TASK_TO_EXECUTE
)
public class CouponTaskDelayExecuteConsumer implements RocketMQListener<MessageWrapper<CouponTaskDelayExecuteEvent>> {
    private final CouponTaskExecuteProducer couponTaskExecuteProducer;

    @Override
    public void onMessage(MessageWrapper<CouponTaskDelayExecuteEvent> couponTaskDelayExecuteEventMessageWrapper) {
        CouponTaskDelayExecuteEvent message = couponTaskDelayExecuteEventMessageWrapper.getMessage();

        CouponTaskExecuteEvent event = CouponTaskExecuteEvent.builder()
                .couponTaskId(message.getCouponTaskId())
                .build();

        couponTaskExecuteProducer.sendMessage(event);
    }
}
